package com.lzclass.servlet.whyservlet;

import com.alibaba.fastjson.JSON;
import com.lzclass.pojo.BackMessage;
import com.lzclass.service.whyservice.ArcitleService;
import com.lzclass.util.ServiceUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

//添加评论
//需要参数：aid，uid,messageinfo,token
//返回参数:添加成功/添加失败
@WebServlet("/user/tianjialiuyan")
public class BackmessageByallServlet extends HttpServlet {
    private ArcitleService arcitleService = (ArcitleService) ServiceUtil.getService("arcitleServiceImpl");
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String uid = req.getParameter("uid");
        Integer integer = Integer.parseInt(uid);
        String aid = req.getParameter("aid");
        int aid1 = Integer.parseInt(aid);
        String messageinfo = req.getParameter("messageinfo");
        Date now = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String messagetime=simpleDateFormat.format(now);
        BackMessage backMessage = new BackMessage();
        backMessage.setAid(aid1);
        backMessage.setUid(integer);
        backMessage.setMessageinfo(messageinfo);
        backMessage.setMessagetime(messagetime);

        String addmessage = arcitleService.addmessage(backMessage);

        resp.setContentType("text/html;charset=UTF-8");
        resp.getWriter().write(addmessage);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
